//直接得到scroll事件，并且一次touch只响应一次

class ScrollObj {
    bind(obj:egret.DisplayObject) {
        obj.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
        obj.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.onTouchMove,this)
        //obj.addEventListener(egret.TouchEvent.TOUCH_END,this.onTouchEnd,this)
        //obj.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.onTouchRelease,this)
    }

    begin_x = 0;
    begin_y = 0;
    onTouchBegin(event:egret.TouchEvent){
        this.begin_x = event.localX;
        this.begin_y = event.localY;
        this.touching = false;
    }

    deltax = 20;
    deltay = 20;

    touching = false;
    onTouchMove(event:egret.TouchEvent){
        if (this.touching)
            return;

        let x = event.localX;
        let y = event.localY;
        let dx = x - this.begin_x;
        let dy = y - this.begin_y;

        if (Math.abs(dx) > this.deltax)
        {
            if (this.funcScrollX)
            {
                this.touching = true;
                this.funcScrollX(dx);
            }
        }
        if (Math.abs(dy) > this.deltay)
        {
            if (this.funcScrollY)
            {
                this.touching = true;
                this.funcScrollY(dx);
            }
        }
    }

    funcScrollX:Function;
    funcScrollY:Function;

    // onTouchEnd(event:egret.TouchEvent){
    //     this.touching = false;
    // }
    // onTouchRelease(event:egret.TouchEvent){
    //     this.touching = false;
    // }
}


